home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / gold / Msg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.7 KB  |  75 lines

  1. /*
  2.  * The original copyright owners of the accompanying source code files have
  3.  * agreed to place such code into the public domain.  Accordingly, anyone
  4.  * who receives or obtains a copy of such source code is freely entitled to
  5.  * reproduce, use and otherwise exploit such code (including the right to
  6.  * make derivative works), at his/her own risk and expense, without any
  7.  * obligation or liability to the original copyright owners.
  8.  *
  9.  * We would appreciate (but do not require) that the following message be
  10.  * included in any derivative works:
  11.  *
  12.  * "Portions of this program were developed by Peter Broadwell, Rob Myers
  13.  * and Robin Schaufler while working in Silicon Valley."
  14.  *
  15.  * The accompanying source code files and related documentation materials
  16.  * are distributed on an "AS IS" basis, without any warranties or
  17.  * guarantees of any kind.  All implied warranties, including the implied
  18.  * warranties of merchantability and of fitness for any particular purpose,
  19.  * are expressly disclaimed.
  20.  */
  21. #include <stdio.h>
  22. #include "class.h"
  23.  
  24. char * lastClass = 0;
  25. char * lastSelector = 0;
  26. char * lastReceiver = 0;
  27.  
  28.    /*
  29.     * instance message dispatcher
  30.     */
  31.     char *
  32. Msg(receiver, selector, argtype, arg)
  33.     register inst    *receiver;
  34.     register int    selector;
  35.     int        argtype;
  36.     char    *arg;
  37. #ifdef BLAZING_SADDLES
  38. {
  39.     register classFcn fcn;  /* ptr to function within class function array */
  40.     register char *retVal = (char *)1;    /* value returned from function */
  41.  
  42.     if (fcn = ((classFcn *)receiver->classFcns)[selector]) {
  43.     retVal = (char *)((*fcn)(receiver, argtype, arg)); 
  44.     }
  45. }
  46. #else
  47. {
  48.     classFcn    *fcnPtr;    /* ptr to function array within class description */
  49.     classFcn fcn;          /* ptr to function within class function array    */
  50.     char *retVal = (char *)1;        /* value returned from function */
  51.  
  52.     if (receiver) {
  53. lastReceiver = (char *)receiver;
  54. lastClass = (char *)receiver->myClass->classId;
  55.     if (fcnPtr = receiver->classFcns) {         /* assign, test for NULL */
  56. lastSelector = (char *)selector;
  57.         if ((selector >= 0) && (selector < receiver->nFcns)) {
  58.         if (fcn = fcnPtr[selector]) {     /* assign, test for NULL */
  59.             retVal = (char *)((*fcn)(receiver, argtype, arg)); 
  60.         } else
  61. #ifdef LOUD
  62.             fprintf(stderr,"Msg: selector %d; NULL fcn\n",selector)
  63. #endif
  64.             ;
  65.         } else
  66.         fprintf(stderr,"Msg: selector %d out of range receiver=%x id=%d nFcns=%d\n", selector,receiver,receiver->myClass->classId,receiver->nFcns);
  67.     } else
  68.         fprintf(stderr,"Msg: receiver %x has NULL classFcns selector=%d id=%d\n",
  69.             receiver,selector,receiver->myClass->classId);
  70.     } else
  71.     fprintf(stderr,"Msg: NULL receiver selector=%d\n",selector);
  72.     return retVal;
  73. }
  74. #endif /* BLAZING_SADDLES */
  75.